package com.wetao.lib_common.greendao.dao;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.wetao.lib_common.greendao.model.WireQuestionPicture;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "WIRE_QUESTION_PICTURE".
*/
public class WireQuestionPictureDao extends AbstractDao<WireQuestionPicture, Long> {

    public static final String TABLENAME = "WIRE_QUESTION_PICTURE";

    /**
     * Properties of entity WireQuestionPicture.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property BookId = new Property(1, Integer.class, "bookId", false, "BOOK_ID");
        public final static Property PageNumber = new Property(2, Integer.class, "pageNumber", false, "PAGE_NUMBER");
        public final static Property SectionNo = new Property(3, Integer.class, "sectionNo", false, "SECTION_NO");
        public final static Property OwnerNo = new Property(4, Integer.class, "ownerNo", false, "OWNER_NO");
        public final static Property PageSerial = new Property(5, String.class, "pageSerial", false, "PAGE_SERIAL");
        public final static Property Min_w = new Property(6, Float.class, "min_w", false, "MIN_W");
        public final static Property Max_w = new Property(7, Float.class, "max_w", false, "MAX_W");
        public final static Property Min_h = new Property(8, Float.class, "min_h", false, "MIN_H");
        public final static Property Max_h = new Property(9, Float.class, "max_h", false, "MAX_H");
        public final static Property PageIndex = new Property(10, Integer.class, "pageIndex", false, "PAGE_INDEX");
        public final static Property OssPath = new Property(11, String.class, "ossPath", false, "OSS_PATH");
        public final static Property WireQuestionId = new Property(12, Long.class, "wireQuestionId", false, "WIRE_QUESTION_ID");
    }

    private Query<WireQuestionPicture> wireQuestion_WireQuestionPictureListQuery;

    public WireQuestionPictureDao(DaoConfig config) {
        super(config);
    }
    
    public WireQuestionPictureDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"WIRE_QUESTION_PICTURE\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"BOOK_ID\" INTEGER," + // 1: bookId
                "\"PAGE_NUMBER\" INTEGER," + // 2: pageNumber
                "\"SECTION_NO\" INTEGER," + // 3: sectionNo
                "\"OWNER_NO\" INTEGER," + // 4: ownerNo
                "\"PAGE_SERIAL\" TEXT," + // 5: pageSerial
                "\"MIN_W\" REAL," + // 6: min_w
                "\"MAX_W\" REAL," + // 7: max_w
                "\"MIN_H\" REAL," + // 8: min_h
                "\"MAX_H\" REAL," + // 9: max_h
                "\"PAGE_INDEX\" INTEGER NOT NULL ," + // 10: pageIndex
                "\"OSS_PATH\" TEXT," + // 11: ossPath
                "\"WIRE_QUESTION_ID\" INTEGER NOT NULL );"); // 12: wireQuestionId
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"WIRE_QUESTION_PICTURE\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, WireQuestionPicture entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Integer bookId = entity.getBookId();
        if (bookId != null) {
            stmt.bindLong(2, bookId);
        }
 
        Integer pageNumber = entity.getPageNumber();
        if (pageNumber != null) {
            stmt.bindLong(3, pageNumber);
        }
 
        Integer sectionNo = entity.getSectionNo();
        if (sectionNo != null) {
            stmt.bindLong(4, sectionNo);
        }
 
        Integer ownerNo = entity.getOwnerNo();
        if (ownerNo != null) {
            stmt.bindLong(5, ownerNo);
        }
 
        String pageSerial = entity.getPageSerial();
        if (pageSerial != null) {
            stmt.bindString(6, pageSerial);
        }
 
        Float min_w = entity.getMin_w();
        if (min_w != null) {
            stmt.bindDouble(7, min_w);
        }
 
        Float max_w = entity.getMax_w();
        if (max_w != null) {
            stmt.bindDouble(8, max_w);
        }
 
        Float min_h = entity.getMin_h();
        if (min_h != null) {
            stmt.bindDouble(9, min_h);
        }
 
        Float max_h = entity.getMax_h();
        if (max_h != null) {
            stmt.bindDouble(10, max_h);
        }
        stmt.bindLong(11, entity.getPageIndex());
 
        String ossPath = entity.getOssPath();
        if (ossPath != null) {
            stmt.bindString(12, ossPath);
        }
        stmt.bindLong(13, entity.getWireQuestionId());
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, WireQuestionPicture entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Integer bookId = entity.getBookId();
        if (bookId != null) {
            stmt.bindLong(2, bookId);
        }
 
        Integer pageNumber = entity.getPageNumber();
        if (pageNumber != null) {
            stmt.bindLong(3, pageNumber);
        }
 
        Integer sectionNo = entity.getSectionNo();
        if (sectionNo != null) {
            stmt.bindLong(4, sectionNo);
        }
 
        Integer ownerNo = entity.getOwnerNo();
        if (ownerNo != null) {
            stmt.bindLong(5, ownerNo);
        }
 
        String pageSerial = entity.getPageSerial();
        if (pageSerial != null) {
            stmt.bindString(6, pageSerial);
        }
 
        Float min_w = entity.getMin_w();
        if (min_w != null) {
            stmt.bindDouble(7, min_w);
        }
 
        Float max_w = entity.getMax_w();
        if (max_w != null) {
            stmt.bindDouble(8, max_w);
        }
 
        Float min_h = entity.getMin_h();
        if (min_h != null) {
            stmt.bindDouble(9, min_h);
        }
 
        Float max_h = entity.getMax_h();
        if (max_h != null) {
            stmt.bindDouble(10, max_h);
        }
        stmt.bindLong(11, entity.getPageIndex());
 
        String ossPath = entity.getOssPath();
        if (ossPath != null) {
            stmt.bindString(12, ossPath);
        }
        stmt.bindLong(13, entity.getWireQuestionId());
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public WireQuestionPicture readEntity(Cursor cursor, int offset) {
        WireQuestionPicture entity = new WireQuestionPicture( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getInt(offset + 1), // bookId
            cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2), // pageNumber
            cursor.isNull(offset + 3) ? null : cursor.getInt(offset + 3), // sectionNo
            cursor.isNull(offset + 4) ? null : cursor.getInt(offset + 4), // ownerNo
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // pageSerial
            cursor.isNull(offset + 6) ? null : cursor.getFloat(offset + 6), // min_w
            cursor.isNull(offset + 7) ? null : cursor.getFloat(offset + 7), // max_w
            cursor.isNull(offset + 8) ? null : cursor.getFloat(offset + 8), // min_h
            cursor.isNull(offset + 9) ? null : cursor.getFloat(offset + 9), // max_h
            cursor.getInt(offset + 10), // pageIndex
            cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // ossPath
            cursor.getLong(offset + 12) // wireQuestionId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, WireQuestionPicture entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setBookId(cursor.isNull(offset + 1) ? null : cursor.getInt(offset + 1));
        entity.setPageNumber(cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2));
        entity.setSectionNo(cursor.isNull(offset + 3) ? null : cursor.getInt(offset + 3));
        entity.setOwnerNo(cursor.isNull(offset + 4) ? null : cursor.getInt(offset + 4));
        entity.setPageSerial(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setMin_w(cursor.isNull(offset + 6) ? null : cursor.getFloat(offset + 6));
        entity.setMax_w(cursor.isNull(offset + 7) ? null : cursor.getFloat(offset + 7));
        entity.setMin_h(cursor.isNull(offset + 8) ? null : cursor.getFloat(offset + 8));
        entity.setMax_h(cursor.isNull(offset + 9) ? null : cursor.getFloat(offset + 9));
        entity.setPageIndex(cursor.getInt(offset + 10));
        entity.setOssPath(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11));
        entity.setWireQuestionId(cursor.getLong(offset + 12));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(WireQuestionPicture entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(WireQuestionPicture entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(WireQuestionPicture entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "wireQuestionPictureList" to-many relationship of WireQuestion. */
    public List<WireQuestionPicture> _queryWireQuestion_WireQuestionPictureList(Long wireQuestionId) {
        synchronized (this) {
            if (wireQuestion_WireQuestionPictureListQuery == null) {
                QueryBuilder<WireQuestionPicture> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.WireQuestionId.eq(null));
                wireQuestion_WireQuestionPictureListQuery = queryBuilder.build();
            }
        }
        Query<WireQuestionPicture> query = wireQuestion_WireQuestionPictureListQuery.forCurrentThread();
        query.setParameter(0, wireQuestionId);
        return query.list();
    }

}
